<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


namespace Admin\Controller;

use Think\Controller;

class ApplyController extends CommonController {

    function index() {
        $User = M('Join'); // 实例化User对象
        $keywords = $_REQUEST['keys'];
        if ($keywords) {
            $map['name'] = array('like', '%' . $keywords . '%');
            $map['tel'] = array('eq', $keywords); //多条件
            $map['_logic'] = 'OR';
            $where['_complex'] = $map;
        }
        $p = getpage($User, $where, C('List_Len'));
        foreach ($map as $key => $val) {
            $Page->parameter .= "$key=" . urlencode($val) . "&";
        }
        $list = $User->where($map)->order('ctime desc')->select();
        $this->assign('list', $list); // 赋值数据集
        $this->assign('page', $p->show()); // 赋值分页输出
        $this->display();
    }

    //审核
    function checkInfo() {
        $id = $_REQUEST['id'];
        $status = $_REQUEST['status'];
        $User = M('Join'); // 实例化User对象
        $card_No = $User->where('id=' . $id)->getField('card_no');
        $state = $User->where('id=' . $id)->save(array('status' => $status, 'checktime' => $this->crtTime()));
        if ($state) {
            if ($status == 2) {
                $qty = addCredits($card_No, 1000); //钾肥分
                if ($qty) {
                    $arr = array(
                        'open_id' => 'apply',
                        'score' => 1000,
                        'card_no' => $card_No,
                        'ctime' => $this->crtTime(),
                    );
                    M('Score')->add($arr);
                }
            }
            $this->success('数据已保存！', "index");
        } else {
            $this->error('数据未保存！');
        }
    }

}

?>
